<div class="bjui-pageHeader">
    <table class="table table-bordered table-hover table-striped table-top">
        <!-- 商品名称 	商品货号 	数量(2) 	零售单价 	颜色规格  -->
        <tr>
            <th>换货商品名称</th>
            <th>换货商品货号</th>
			<th>颜色规格</th>
            <th>换货数量</th>
            <th>换货原因</th>
            <th>换货详情</th>
        </tr>
        <tr>
            <td>{$service_goods.name}</td>
            <td>{$service_goods.sn}</td>
			<td>颜色：{$service_goods.color_name}<br />规格：{$service_goods.spec_name}</td>
            <td>{$service_goods.return_num}</td>
            <td>{$service_goods.return_reason}</td>
            <td>{$service_goods.details}</td>
        </tr>
    </table>
	<form id="pagerForm" data-toggle="ajaxsearch" action="{:U('searchGoods')}" method="post">
        <!-- <input type="hidden" name="inputName" value="{:I('request.inputName')}"> -->
        <input type="hidden" name="service_sn" value="{:I('request.service_sn')}">
        <input type="hidden" name="orderGoodsId" value="{:I('request.orderGoodsId')}">
        <div class="bjui-searchBar">
            <select name="key" data-toggle="selectpicker">
                <option value="name"
                <?php echo I("key")=="name" ? "selected='true'" : "";?>>名称</option>
                <option value="sn"
                <?php echo I("key")=="sn" ? "selected='true'" : "";?>>货号</option>
                <!-- <option value="bar_code"
                <?php echo I("key")=="bar_code" ? "selected='true'" : "";?>>条码</option>
                -->
            </select>
            <input type="text" value="{:I('goodsName')|I('value')}" name="value" size="30">
            <button type="submit" class="btn-default" data-icon="search">查询</button>
            <a class="btn btn-orange" href="javascript:;"
               onclick="$.CurrentDialog.dialog('reloadForm', true, {type:'GET',data:{orderGoodsId:'{:I('request.orderGoodsId')}',service_sn:'{:I('request.service_sn')}'}})"
               data-icon="undo">返回</a>
        </div>
    </form>
    
</div>
<div class="bjui-pageContent tableContent">
   <table class="table table-bordered table-hover table-striped table-top" id="searchContent">
        <?php if(empty($list)):?>
            <thead>
            <tr>
                <th>商品名称</th>
                <th>单价</th>
                <th>零售价</th>
                <th>数量</th>
                <th align="center">操作</th>
            </tr>
            </thead>
            <tbody>
             <?php if($barter_goods):?>
            <tr>
               <td>
                    {$barter_goods.name}
                    <br />
                    货号：{$barter_goods.sn}
                </td>
                <td>{$barter_goods.goods_price}</td>
                <td>{$barter_goods.retail_price}</td>
                <td>{$barter_goods.return_num}</td>
                <td align="center">
                    颜色：{$barter_goods.color_name}，规格：{$barter_goods.spec_name}
                    <hr style="border-top:1px solid #185598; margin: 5px;" />
                    {$barter_goods.bar_code}
                    <br />
                    <a type="button" class="btn btn-red"
                       href="{:U('AfterSales/delgoods?service_sn='.$service_goods['service_sn'].'&orderGoodsId='.$service_goods['order_goods_id'])}"
                       data-toggle="doajax" data-confirm-msg="确认删除该商品？"
                       data-callback="delGoodsCallBack">删除</a>
                    <a class="btn btn-green" href="{:U('searchBarCode?goodsId='.$barter_goods['goods_id'].'&orderGoodsId='.$barter_goods['order_goods_id'].'&service_sn='.$barter_goods['service_sn'])}"
                       data-toggle="ajaxload" data-target="#searchContent">修改</a>
                </td>
                <input type="hidden" name="barCodeId" value="{$orderGoodsArr.id}">
                <input type="hidden" name="goodsId" value="{$orderGoodsArr.goods_id}">
            </tr>
            <?php else:?>
            <tr>
                <td colspan="5" align="center">没有添加商品!</td>
            </tr>
            <?php endif;?>
            </tbody>
           <?php else:?>
            <thead>
            <tr>
                <th>商品名称</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($list as $arr):?>
            <tr>
                <td>
                    <a href="{:U('searchBarCode?goodsId='.$arr['id'].'&orderGoodsId='.I('request.orderGoodsId').'&service_sn='.I('request.service_sn'))}"
                       data-toggle="ajaxload" data-target="#searchContent">{$arr.name}</a>
                </td>
            </tr>
            <?php endforeach;?>
            </tbody>
        <?php endif;?>
    </table>
</div>
<script>

    /**
     * [chooseBarCode 选择对应的条码商品]
     * @param  {[type]} obj [description]
     * @return {[type]}     [description]
     */
   
 /**
     * [chooseBarCode 选择对应的条码商品]
     * @param  {[type]} obj [description]
     * @return {[type]}     [description]
     */
    function chooseBarCode(obj) {
        var tableBarCode = $(obj).parent().parent();
        var options = {};
        options['url'] = "{:U('AfterSales/addGoods')}";
        options['type'] = "POST";
		options['callback'] = "addGoodsCallBack2";
        options['data'] = {};
        options['data']['service_sn'] = "{$service_goods.service_sn}";   // 订单售后记录号
        options['data']['order_goods_id'] = "{:I('request.orderGoodsId')}";   // order_goods表id
        options['data']['number'] = tableBarCode.find("input[type=text][data-toggle=spinner]").val();
        options['data']['retail_price'] = tableBarCode.find("input[type=text][name=retail_price]").val();
        options['data']['bar_code_id'] = tableBarCode.find("input[type=hidden][name=barCodeId]").val();
        options['data']['goods_id'] = tableBarCode.find("input[type=hidden][name=goodsId]").val();
          if(options['data']['number']!='{$service_goods.return_num}'){
            $(this).alertmsg('error', '商品数量不符合商品原有的指定数量');
            return;
        }
        $(obj).bjuiajax('doAjax', options);
    }
	
	    /**
     * 添加商品回调函数
     * @param data
     */
    function addGoodsCallBack2(data) { // data为返回的数据
        if (data && data[BJUI.keys.statusCode] == BJUI.statusCode.ok) {
//            $.CurrentDialog.dialog('closeCurrent'); // 关闭当前弹窗
            $.CurrentDialog.dialog('reload'); // 关闭当前弹窗
			$.CurrentNavtab.navtab('reload');          // 刷新当前窗口
        } else {
            $(this).alertmsg('error', data.message);
        }
    }
	
	 /**
     * 删除商品回调函数
     * @param data
     */
    function delGoodsCallBack(data){
        console.log(data);
        if(data && data.statusCode == 200){
			$.CurrentDialog.dialog('reload'); // 关闭当前弹窗
            $.CurrentNavtab.navtab('reload');          // 刷新当前窗口
        }else{
            $(this).alertmsg('error', data.message);
        }
    }

</script>